//
//  XDTabBarView.m
//  ocweibo
//
//  Created by lucy on 2016/10/24.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

#import "XDTabBarView.h"
#import "UIButton+XDButton.h"


@interface XDTabBarView ()

@property(nonatomic,strong)UIButton* composeBtn;

@end

@implementation XDTabBarView

#pragma mark-初始化方法
- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    [self setupUI];

    return self;
}


#pragma mark-初始化视图
- (void)setupUI{
    
    //新加的按钮
    _composeBtn = [[UIButton alloc]init];
    [self addSubview:_composeBtn];
    [_composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [_composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    
    [_composeBtn addTarget:self action:@selector(composeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_composeBtn sizeToFit];


    
}


#pragma mark-中间按钮点击事件
- (void)composeBtnClick:(UIButton*)button{


//    NSLog(@"中间的按钮被点击了");
    if (_btnBlock) {
        _btnBlock();
    }
    

}


#pragma mark-按钮布局
- (void)layoutSubviews{
    [super layoutSubviews];
//    NSLog(@"%@",self.subviews);
    NSInteger index = 0;
    CGFloat W = 0.2 * SCREENW;
    Class cls = NSClassFromString(@"UITabBarButton");
    for (NSInteger i=0; i<self.subviews.count; i++) {
        if ([self.subviews[i] isKindOfClass:cls]) {
            CGRect rect = self.subviews[i].frame;
            rect.size.width = W;
            rect.origin.x = index * W;
            self.subviews[i].frame = rect;
            index++;
            if (index == 2) {
                index++;
            }
        }

    }
    
    //按钮的frame设置
    CGFloat x = SCREENW * 0.5-30;
    CGFloat y = self.frame.size.height* 0.5-22;
    _composeBtn.frame= CGRectMake(x, y, 64, 44);
    
}



@end

























